fix: importing msw/experimental throws runtime error#2702
fix: importing msw/experimental throws runtime error#2702christoph-fricke wants to merge 1 commit intomswjs:mainfrom
Conversation
📝 WalkthroughWalkthroughThis change converts Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
aee80f6 to
0c34cc6
Compare
| @@ -1,12 +1,12 @@ | |||
| import { pruneGetRequestBody } from './pruneGetRequestBody' | |||
| import type { ServiceWorkerIncomingRequest } from '../glossary' | |||
There was a problem hiding this comment.
This type does not exist in glossary...
0c34cc6 to
fb8cda5
Compare
| @@ -1,4 +1,5 @@ | |||
| export { defineNetwork, DefineNetworkOptions } from './define-network' | |||
| export { defineNetwork } from './define-network' | |||
| export type { DefineNetworkOptions } from './define-network' | |||
There was a problem hiding this comment.
For some reason it has to be this separate export type {....}. export {..., type ...} appears to not strip the interface from the output /lib/core/experimental/index.mjs file (unless I was looking at some cached file...).
The new network-source API is not usable as soon as a project tries to import from
msw/experimental. It crashes with a runtime error:This PR fixes the problem by using a type export in src/core/experimental/index.ts to ensure
DefineNetworkOptionsis stripped from the JS output.I initially tried to prevent such problems in the future by enabling
verbatimModulesyntax intsconfig.base.jsonand fixing multiple TS errors reported bypnpm exec tsc --noEmit -p src/tsconfig.src.json, but it caused strange problems in CI.Besides this, there appear to be multiple TS errors in the project. Some picked in the editor, some only reported by checking with one of the various TS config files such as
pnpm exec tsc --noEmit -p ./tsconfig.test.unit.json. Some source code errors I noticed:It does not look like the CI finds and reports the errors. Are you aware of these existing TypeScript problems?